<template>
  <div name="fn-toast-pop">
    <div class="fn-toast" v-show="visible" :class="customClass"
         :style="{ 'padding': iconClass === '' ? '.66rem .5rem' : '20px' }">
      <i class="fn-toast-icon" :class="iconClass" v-if="iconClass !== ''"></i>
      <span class="fn-toast-text"
            :style="{ 'padding': iconClass === '' ? '.5rem .68rem' : '20px' }">{{ message }}</span>
    </div>
  </div>
</template>

<style lang="less" scoped>
  @b-width        : 75 * 1rem;
  .fn-toast {
    position: fixed;
    width: 100%;
    color: #fff;
    box-sizing: border-box;
    text-align: center;
    -webkit-transition: opacity .3s linear;
    transition: opacity .3s linear;
    z-index: 999999;
  }

  .fn-toast.is-placebottom {
    bottom: 50px;
    left: 50%;
    -webkit-transform: translate(-50%);
    transform: translate(-50%)
  }

  .fn-toast.is-placemiddle {
    left: 50%;
    top: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%)
  }

  .fn-toast.is-placetop {
    top: 50px;
    left: 50%;
    -webkit-transform: translate(-50%);
    transform: translate(-50%)
  }

  .fn-toast-icon {
    display: block;
    text-align: center;
    font-size: 56px
  }

  .fn-toast-text {
    font-size: 28/@b-width;
    display: inline-block;
    text-align: center;
    border-radius: 5px;
    background: rgba(0, 0, 0, .7);
    min-width: 44%;
    /*white-space: nowrap;*/
  }

  .fn-toast-pop-enter, .fn-toast-pop-leave-active {
    opacity: 0
  }
</style>

<script type="text/babel">
  export default {
    props: {
      message: String,
      className: {
        type: String,
        default: ''
      },
      position: {
        type: String,
        default: 'middle'
      },
      iconClass: {
        type: String,
        default: ''
      }
    },
    data() {
      return {
        visible: false
      };
    },
    computed: {
      customClass() {
        var classes = [];
        switch (this.position) {
          case 'top':
            classes.push('is-placetop');
            break;
          case 'bottom':
            classes.push('is-placebottom');
            break;
          default:
            classes.push('is-placemiddle');
        }
        classes.push(this.className);
        return classes.join(' ');
      }
    }
  };
</script>
